import 'dart:ui';

import 'package:flutter/material.dart';

class SalesBox extends StatefulWidget {
  final Map salesBox;

  const SalesBox({Key key, this.salesBox}) : super(key: key);

  @override
  _SalesBoxState createState() => _SalesBoxState();
}

class _SalesBoxState extends State<SalesBox> {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
      ),
      child: _items(context),
    );
  }

  Widget _items(BuildContext context) {
    if (widget.salesBox == null) {
      return null;
    }

    List<Widget> list = [];
    list.add(_doubleItem(context, true, false));
    list.add(_doubleItem(context, false, false));
    list.add(_doubleItem(context, false, true));

    return Column(
      children: [
        Container(
          height: 44,
          decoration: BoxDecoration(
            border: Border(
              bottom: BorderSide(width: 1, color: Color(0xfff2f2f2)),
            ),
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Image.asset(
                'images/bg0.jpeg',
                height: 15,
                width: 100,
                fit: BoxFit.fill,
              ),
              Container(
                padding: EdgeInsets.fromLTRB(10, 1, 8, 1),
                margin: EdgeInsets.only(right: 7),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(12),
                  gradient: LinearGradient(
                    colors: [
                      Color(0xffff4e63),
                      Color(0xffff6cc9),
                    ],
                    begin: Alignment.centerLeft,
                    end: Alignment.centerRight,
                  ),
                ),
                child: GestureDetector(
                  onTap: () {},
                  child: Text(
                    '获得更多福利 >',
                    style: TextStyle(color: Colors.white, fontSize: 12),
                  ),
                ),
              ),
            ],
          ),
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: list.sublist(0, 1),
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: list.sublist(1, 2),
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: list.sublist(2, 3),
        )
      ],
    );
  }

  Widget _doubleItem(BuildContext context, bool isBig, bool isLast) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        _item(context, isBig, true, isLast),
        _item(context, isBig, false, isLast),
      ],
    );
  }

  Widget _item(BuildContext context, bool isBig, bool isLeft, bool isLast) {
    BorderSide borderSide = BorderSide(width: 0.8, color: Color(0xfff2f2f2));
    return GestureDetector(
      onTap: () {
        print('object');
      },
      child: Container(
        decoration: BoxDecoration(
          border: Border(
            right: isLeft ? borderSide : BorderSide.none,
            bottom: isLast ? borderSide : BorderSide.none,
          ),
        ),
        child: Image.asset(
          'images/Release.png',
          fit: BoxFit.fill,
          width: MediaQuery.of(context).size.width / 2 - 8,
          height: isBig ? 129 : 80,
        ),
      ),
    );
  }
}
